/**
 * @file       Frame.h
 * @brief      TODO
 * @author     Huabo Zheng
 * @date       Jan 12, 2012
 * @Copyright  2012, www.netgear.com Inc. All rights reserved.
 */

#ifndef FRAME_H_
#define FRAME_H_

#include <string>
#include "Rect.h"
#include "EventHandler.h"
#include "lcd/IDisplay.h"
#include <vector>
#include "AppEvent.h"

namespace NS_LCD_AFW
{

class CPanel;
class IDisplay;
class CContext;

class CFrame: public CEventHandler
{
public:
	CFrame();

public:
	void destory();

protected:
	virtual ~CFrame();

public:
	int create(const std::string &name, const CRect &rect = DEFAULT_RECT,
			CFrame *pParent = NULL, CContext *pContext = NULL);
	int show();

public:
	//getter and setter
	CRect & getRect();

	std::string getName() const;

	int setRect(CRect rect);

	int setPosition(const CPoint &pt);
	CPoint getPosition() const;

	bool isFocusable() const;
	bool isHightlightable() const;
	bool isCursorable() const;

	bool hasFocus() const;
	int setFocus(bool hasFocus);

	bool isHightlight() const;
	int setHightlight(bool bHightlight);

	bool isVisible() const;
	int setVisible(bool bVisible);

	bool hasCursor() const;
	int setCursor(bool bShow);

	int postEvent(int eventId, int param);
	int postEvent(CAppEvent *pEvent);

	int setCenter();

	virtual int invalidate();
	virtual int invalidateRect(const CRect &rect);
	virtual int onDraw(IDisplay *pDisplay);

	CFrame *getParent() const;
protected:

	void setFocusable(bool bFocusable);
	void setHightlightable(bool bHightlightable);
	void setCursorable(bool bCursorable);

public:
	virtual int notify(IEvent *pEvent);

private:
	void setParent(CFrame *pParent);
	void setName(std::string strName);

protected:
	//virtual

	virtual void preCreate();
	virtual void preShow();
	virtual int onCreate();
	virtual void onSetFocus();
	virtual void onLostFocus();
	virtual void onHightlight();
	virtual void onUnHightlight();
	virtual void onSize(const CRect &oldRect, const CRect &newRect);
	virtual void onMove(const CPoint &oldPosition, const CPoint &newPosition);
	virtual void onVisible();
	virtual void onInvisible();
	virtual void onShowCursor();
	virtual void onHideCursor();

public:

	virtual int onLeftKeyPress();
	virtual int onRightKeyPress();
	virtual int onUpKeyPress();
	virtual int onDownKeyPress();
	virtual int onEnterKeyPress();
	virtual int onEscKeyPress();
	virtual int onClose();

private:

	bool m_bFocusable;
	bool m_bHasFocus;
	bool m_bHightlightable;
	bool m_bIsHightlight;
	bool m_bIsVisible;
	bool m_bCursorable;
	bool m_bHasCursor;
	CFrame* m_pParent;
	CRect m_frameRect;
	CPoint m_position;
	std::string m_strFrameName;

private:
	DISABLE_COPY_CONSTRUCTOR_AND_ASSIGN_REFERENCE(CFrame);
};
typedef std::vector<CFrame *> CFramePtrArray;
} /* namespace NS_LCD_AFW */
#endif /* FRAME_H_ */
